<?php
/* $Id: funcs.php,v 1.1 JOP $ */
/**
 * @package Issue-Tracker
 * @subpackage Docs
 */

if (strpos($_SERVER['PHP_SELF'],basename(__FILE__)) !== false) 
{print "Direct module access forbidden.";exit;}


function get_doc_cat_level($cid,$offset=null)
{
  $cid_level = getfield('z_doc_categories','level','cid',$cid);
  if (!empty($offset)) {
  return $cid_level + $offset;
  } else {
  return $cid_level;
  }
}
/* }}} */

function get_parent_cid($cid)
{
  $parent_cid = getfield('z_doc_categories','parent_cid','cid',$cid);
  if (!empty($parent_cid)) {
     return $parent_cid;
  } else {
     return '0';
  }
}
/* }}} */

function get_sublevel_cats($cid=null)
{

  global $dbi;

if (!empty($cid)) {
  $level = get_doc_cat_level($cid,"1");
  } else {
  $level = "0";
  }

  $sub_cats = array();

  $sql  = "SELECT cid ";
  $sql .= "FROM z_doc_categories ";
  $sql .= "WHERE level='$level' ";
if (!empty($cid)) {
  $sql .= "AND parent_cid='$cid' ";
  }
  $sql .= "ORDER BY text";
  $result = $dbi->query($sql);

  if ($dbi->num_rows($result) > 0) {
    while (list($cid) = $dbi->fetch($result)) {
      array_push($sub_cats,$cid);
    }
    $dbi->free($result);
    return $sub_cats;
    } else {
    return;
    }
}
/* }}} */

function get_category_docs($cid)
{

  global $dbi;

  $docs = array();

  $sql  = "SELECT did ";
  $sql .= "FROM z_docs ";
  $sql .= "WHERE cid='$cid'";
    $result = $dbi->query($sql);
    if ($dbi->num_rows($result) > 0) {
    while (list($did) = $dbi->fetch($result)) {
      array_push($docs,$did);
    }
    $dbi->free($result);
    return $docs;
    } else {
    return;
    }
}
/* }}} */

?>